<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class WhmAccountAddForm extends CFormModel
{
	public $id_account;
	public $domain;
	public $username;
	public $ipaddress;
	public $id_group;
	public $id_host;
	public $accesshash;
	public $secure;
	public $pass;
	public $pass_secure;
	public $last_cp_update;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			array('username, domain, pass, ipaddress, id_group, id_host, accesshash', 'required'),
			array('id_group, id_host', 'numerical', 'integerOnly'=>true),
			array('domain', 'length', 'max'=>500),
			array('username, ipaddress, accesshash, pass, secure, pass_secure, last_cp_update', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_account, domain, username, ipaddress, id_group, id_host, accesshash, pass, secure, pass_secure, last_cp_update', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels()
	{
		return array(
			'id_account' => t('info', 'Id Account'),
			'domain' => t('info', 'Domain'),
			'username' => t('info', 'Username'),
			'ipaddress' => t('info', 'IP'),
			'id_group' => t('info', 'Id Group'),
			'id_host' => t('info', 'Id Host'),
			'accesshash' => t('info', 'WHM Access Hash Key'),
			'secure' => t('info', 'Secure'),
			'pass_secure' => t('info', 'Password Secure'),
			'pass' => t('info', 'Password'),
			'last_cp_update' => t('info', 'Last Cp Update'),
		);
	}
	
	public function getFieldLabel($field)
	{
		$labels = $this->attributeLabels();
		
		return empty($labels[$field])? '' : $labels[$field];
	}
	
	public function listExistedGroups()
	{
		return CHtml::listData(Group::model()->findAll(), 'id_group', 'namedropdownlabel');
	}
	
	public function listExistedHosts()
	{
		return CHtml::listData(Host::model()->findAll(), 'id_host', 'namedropdownlabel');
	}
	
}